package com.laboratory.service.impl;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.laboratory.model.entity.Lab;
import com.laboratory.model.dto.lab.LabQueryDto;
import com.laboratory.service.LabService;
import com.laboratory.mapper.LabMapper;
import org.springframework.stereotype.Service;

/**
 * 实验室业务逻辑
 */
@Service
public class LabServiceImpl extends ServiceImpl<LabMapper, Lab>
        implements LabService {

    @Override
    public PageInfo<Lab> getAll(Integer pIndex, Integer pSize, LabQueryDto labQueryDto) {
        // 开启分页
        PageHelper.startPage(pIndex, pSize);

        // 条件
        QueryWrapper<Lab> qw = new QueryWrapper<>();

        // 判断传过来的对象是否为空
        if (ObjectUtil.isNotEmpty(labQueryDto)) {
            // 判断实验室是否为空
            if (StrUtil.isNotEmpty(labQueryDto.getName())) {
                qw.like("name", labQueryDto.getName());
            }
        }

        //根据id倒序
        qw.orderByDesc("id");

        return new PageInfo<>(baseMapper.selectList((qw)));
    }
}




